<?php
$server = "localhost";
$name = "root";
$pwd = "123456";
$db = "abcd";

$con = mysqli_connect($server,$name,$pwd,$db);

$name = $_POST['name'];
$age = $_POST['age'];
$ads = $_POST['ads'];
$id = $_POST['id'];

if($con){
    if($id==0){
    $sql = "insert into abc(name,age,ads) values('$name','$age','$ads')";
    }else{
        $sql = "update abc set name='$name',age='$age',ads='$ads' where id = $id";
    }
    $run = mysqli_query($con,$sql);
    if($run){
        echo "数据表数据添加或者更新成功！";
    }else{
        echo "已连接数据库，但未能添加或者更新数据！请稍后再试试！".mysqli_error($con);
    }
    mysqli_close($con);
}else{
    echo "未连接数据库，错误内容：".mysqli_connect_error();
}










